package com.star.sync.elasticsearch.dto.torderinfo;

import com.star.sync.elasticsearch.annotation.EsDataMapping;
import com.star.sync.elasticsearch.execute.torderinfo.TOrderInfoExecute;
import lombok.Data;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import static com.star.sync.elasticsearch.common.EsSearchUtil.esSearchUtil;

/**
 * t_order_info
 *
 * @author
 */
@Data
@EsDataMapping(indexName = "t_order_info", tableName = "t_order_info", type = "parent")
@Service
public class TOrderInfoDTO extends TOrderInfoExecute<TOrderInfoDTO> {


    /**
     * 表主键ID
     */
    private Integer id;

    /**
     * 表业务id
     */
    private String code;

    /**
     * 运单编号
     */
    private String orderBusinessCode;

    /**
     * 货源车辆司机信息子表业务ID
     */
    private String goodsSourceVehicleDriverInfoCode;

    /**
     * 运单资源信息表业务ID
     */
    private String goodSourceCode;

    /**
     * 承运方ID
     */
    private Integer carrierId;

    /**
     * 线路货物关系表ID
     */
    private Integer lineGoodsRelId;

    /**
     * 线路信息ID
     */
    private Integer lineId;

    /**
     * 企业ID
     */
    private Integer companyId;

    /**
     * 项目ID
     */
    private Integer companyProjectId;

    /**
     * 线路编号
     */
    private String lineCode;

    /**
     * 路线名称
     */
    private String lineName;

    /**
     * 路线名称简写
     */
    private String lineShortName;

    /**
     * 起点城市编码
     */
    private String cityFromCode;

    /**
     * 起点名称（简称）
     */
    private String fromName;

    /**
     * 起点坐标
     */
    private String fromCoordinates;

    /**
     * 终点城市编码
     */
    private String cityEndCode;

    /**
     * 终点名称（简称）
     */
    private String endName;

    /**
     * 终点坐标
     */
    private String endCoordinates;

    /**
     * 线路类型
     */
    private String lineType;

    /**
     * 货物信息ID
     */
    private Integer goodsId;

    /**
     * 货物名称
     */
    private String goodsName;

    /**
     * 货物大类CODE
     */
    private String bigKindCode;

    /**
     * 货物单位
     */
    private String goodsUnit;

    /**
     * 货源重量（预估重量）
     */
    private Double estimateGoodsWeight;

    /**
     * 货源单价（预估单价）
     */
    private BigDecimal currentCarriageUnitPrice;

    /**
     * 预估总费用
     */
    private BigDecimal estimateTotalFee;

    /**
     * 发单员账号ID
     */
    private Integer deliverOrderUserId;

    /**
     * 收单员账号ID
     */
    private Integer receiveOrderUserId;

    /**
     * 委托发单员账号ID
     */
    private Integer principalOrderUserId;

    /**
     * 发单时间
     */
    private Date deliverOrderTime;

    /**
     * 收单时间
     */
    private Date receiveOrderTime;

    /**
     * 运单完成时间
     */
    private Date orderFinishTime;

    /**
     * 发货磅单时间
     */
    private Date deliverWeightNotesTime;

    /**
     * 发货磅单重量
     */
    private Double deliverWeightNotesWeight;

    /**
     * 原发重量
     */
    private Double primaryWeight;

    /**
     * 收货磅单时间
     */
    private Date receiveWeightNotesTime;

    /**
     * 收货磅单重量
     */
    private Double receiveWeightNotesWeight;

    /**
     * 卸货重量
     */
    private Double dischargeWeight;

    /**
     * 规则计算的应付运费金额
     */
    private BigDecimal rulePaymentAmount;

    /**
     * 发货磅单照片
     */
    private String deliverWeightNotesPhoto;

    /**
     * 收货磅单照片
     */
    private String receiveWeightNotesPhoto;

    /**
     * 结算重量
     */
    private BigDecimal settledWeight;

    /**
     * 用户确认的应付运费金额
     */
    private BigDecimal userConfirmPaymentAmount;

    /**
     * 签订合同状态
     */
    private String contractStatus;

    /**
     * 运输车辆ID
     */
    private Integer vehicleId;

    /**
     * 运输司机ID
     */
    private Integer endDriverId;

    /**
     * 调度费金额
     */
    private BigDecimal dispatchFee;

    /**
     * 服务费金额
     */
    private BigDecimal serviceFee;

    /**
     * 其他费用金额
     */
    private BigDecimal otherFee;

    /**
     * 总费用金额
     */
    private BigDecimal totalFee;

    /**
     * C端车辆所有人ID
     */
    private Integer endCarOwnerId;

    /**
     * C端经纪人ID
     */
    private Integer endAgentId;

    /**
     * 车辆与司机关系表ID
     */
    private Integer endUserCarRelId;

    /**
     * 发货联系人
     */
    private String deliverGoodsContacter;

    /**
     * 发货联系人电话
     */
    private String deliverGoodsContacterPhone;

    /**
     * 收货联系人
     */
    private String receiveGoodsContacter;

    /**
     * 收货联系人电话
     */
    private String receiveGoodsContacterPhone;

    /**
     * 费用结算模式
     */
    private String feeSettlementWay;

    /**
     * 运单生成类型
     */
    private String orderCreateType;

    /**
     * 运单执行状态
     */
    private String orderExecuteStatus;

    /**
     * 车辆北斗状态
     */
    private String vehicleGpsBdStatus;

    /**
     * 运单支付状态
     */
    private String orderPayStatus;

    /**
     * 企业的承运方
     */
    private String companyEntrust;

    /**
     * 企业的客户
     */
    private String companyClient;

    /**
     * 打包状态 默认0未打包  1已打包
     */
    private String packStatus;

    /**
     * 备注
     */
    private String remark;

    /**
     * 扩展字段1
     */
    private String param1;

    /**
     * 扩展字段2
     */
    private String param2;

    /**
     * 扩展字段3
     */
    private String param3;

    /**
     * 扩展字段4
     */
    private String param4;

    /**
     * 操作方式
     */
    private String operateMethod;

    /**
     * 操作IP地址
     */
    private String operatorIp;

    /**
     * 创建人
     */
    private String createUser;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新人
     */
    private String updateUser;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 是否删除 : 1 true 已删除   ||||   0 false 未删除
     */
    private Boolean enable;

    /**
     * 转历史时间
     */
    private Date turnHistoryTime;

    /**
     * 转历史方式
     */
    private String turnHistoryType;

    /**
     * 转历史操作人
     */
    private String turnHistoryOperator;

    /**
     * 打包后的运费
     */
    private BigDecimal sharePaymentAmount;

    /**
     * 打包后的调度费
     */
    private BigDecimal shareDispatchFee;


    /**
     * orderExecuteStatus
     */
    private TOrderStateNode osn;


    /**
     * orderPayStatus
     */
    private TOrderStateNode tosn;

    /**
     * deliverOrderUserId
     */
    private TAccount ta;


    /**
     * receiveOrderUserId
     */
    private TAccount ta1;


    /**
     * vehicleId
     */
    private TEndCarInfo eci;

    /**
     * endDriverId
     */
    private TEndUserInfo eui;
    /**
     * endCarOwnerId
     */
    private TEndUserInfo euic;
    /**
     * endAgentId
     */
    private TEndUserInfo euis;
    /**
     * wcb.trade_type = 'BYUNFEIZHICHU'
     * AND wcb.id = ( SELECT MAX( id ) FROM t_wallet_change_log WHERE inner_trade_no = toi.`code` )
     */
    private TWalletChangeLog wcb;

    /**
     * wcl.trade_type = 'CTIXIAN'
     * AND wcl.inner_trade_no = toi.`code`
     */
    private TWalletChangeLog wcl;

    /**
     * toi.`code` = occ.order_code
     * AND occ.data_enable = 1
     */
    private TOrderCastChanges occ;

    /**
     * tdci.item_code = occ.capital_transfer_type
     */
    private TDicCatItem tdci;
    /**
     * toi.order_create_type = ctp.item_code
     */
    private TDicCatItem ctp;

    /**
     * toi.carrier_id = tcpi.id1
     */
    private TCarrierInfo tcpi;

    /**
     * tcp.id = toi.company_project_id
     */
    private TCompanyProject tcp;

    /**
     * toi.company_id = tcci.id
     */
    private TCompanyInfo tcci;

    /**
     * ( SELECT MAX( ost.id ) AS
     * id FROM t_order_cast_calc_snapshot ost WHERE toi.`code` = ost.order_code ) = occs.id
     */
    private TOrderCastCalcSnapshot occs;

    /**
     * ON ( SELECT Max( id ) AS id FROM t_order_cast_changes WHERE user_oper = 'PayMent' AND order_code = toi.CODE ) = tocc.id
     */
    private TOrderCastChanges tocc;

    /**
     * toi.`code` = occa.order_code
     * AND occa.data_enable = 1
     */
    private TOrderCastChanges occa;


    /**
     * occa.withdraw_type = txfx.item_code
     */
    private TDicCatItem txfx;

    /**
     * toi.`code` = txr.order_code
     * AND txr.data_enable = 1
     * AND txr.user_oper = 'TX'
     */
    private TOrderCastChanges txr;

    /**
     * toi.`code` = opd.order_code
     * AND opd.`enable` = 0
     */
    private TOrderPackDetail opd;

    /**
     * opd.pack_pay_code = opi.CODE
     * AND opi.`enable` = 0
     */
    private TOrderPackInfo opi;

    /**
     * tosd.id = ( SELECT max( tose.id )
     * FROM t_order_state tose WHERE toi.CODE = tose.order_code AND tose.state_node_value = 'SP0701' )
     */
    private TOrderState tosd;

    /**
     * opi.end_user_id = euipk.id
     */
    private TEndUserInfo euipk;
    /**
     * opi.bank_card_id = tbc.id
     */
    private TBankCard tbc;

    /**
     * tosup.id = ( SELECT MAX( tosb.id ) FROM t_order_state tosb WHERE tosb.state_node_value = 'S0302' AND tosb.order_code = toi.`code` )
     */
    private TOrderState tosup;
    /**
     * tosdown.id = ( SELECT MAX( tosc.id ) FROM t_order_state tosc WHERE tosc.state_node_value = 'S0402' AND tosc.order_code = toi.`code` )
     */
    private TOrderState tosdown;
    /**
     * tos.id = (
     * SELECT
     * MAX( tosa.id )
     * FROM
     * t_order_state tosa
     * WHERE
     * tosa.state_node_value IN ( 'S1300', 'S1301', 'S1302' )
     * AND tosa.order_code = toi.`code`
     * )
     */
    private TOrderState tos;

    /**
     * toi.`code` = occv.order_code
     * AND occv.user_oper = 'Invoice'
     */
    private TOrderCastChanges occv;

    /**
     * ON oal.order_code = toi.CODE
     */
    private TOrderAuditLog oal;

    /**
     * toi.CODE = todl.order_code
     */
    private TOrderDeleteLog todl;

    /**
     * tgsi.line_goods_rel_id = toi.line_goods_rel_id
     */
    private TGoodsSourceInfo tgsi;
    /**
     * ON toi.CODE = toss.order_code
     * AND toss.state_node_value = 'S0101'
     */
    private TOrderState toss;

    private TLineGoodsRel tlgr;

    /**
     * tlgr.capital_transfer_type = tdci2.item_code
     */
    private TDicCatItem tdci2;


    @Override
    public TOrderInfoDTO insert(TOrderInfoDTO tOrderInfoDTO) throws Exception {
        //osn
        if (!StringUtils.isEmpty(tOrderInfoDTO.getOrderExecuteStatus())) {
            SearchRequest searchRequest = new SearchRequest("t_order_state_node");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            sourceBuilder.query(QueryBuilders.termQuery("code.keyword", tOrderInfoDTO.getOrderExecuteStatus()));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            this.setOsn((TOrderStateNode) esSearchUtil.search(searchRequest, TOrderStateNode.class));
        }
        //tosn
        if (!StringUtils.isEmpty(tOrderInfoDTO.getOrderPayStatus())) {
            SearchRequest searchRequest = new SearchRequest("t_order_state_node");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            sourceBuilder.query(QueryBuilders.termQuery("code.keyword", tOrderInfoDTO.getOrderPayStatus()));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            this.setTosn((TOrderStateNode) esSearchUtil.search(searchRequest, TOrderStateNode.class));
        }
        //ta
        if (!StringUtils.isEmpty(tOrderInfoDTO.getDeliverOrderUserId())) {
            GetRequest getRequest = new GetRequest("t_account", tOrderInfoDTO.getDeliverOrderUserId().toString());
            tOrderInfoDTO.setTa((TAccount) esSearchUtil.get(getRequest, TAccount.class));
        }
        //ta1
        if (!StringUtils.isEmpty(tOrderInfoDTO.getReceiveOrderUserId())) {
            GetRequest getRequest = new GetRequest("t_account", tOrderInfoDTO.getReceiveOrderUserId().toString());
            tOrderInfoDTO.setTa1((TAccount) esSearchUtil.get(getRequest, TAccount.class));
        }
        //eci
        if (!StringUtils.isEmpty(tOrderInfoDTO.getVehicleId())) {
            GetRequest getRequest = new GetRequest("t_end_car_info", tOrderInfoDTO.getVehicleId().toString());
            tOrderInfoDTO.setEci((TEndCarInfo) esSearchUtil.get(getRequest, TEndCarInfo.class));
        }
        //eui
        if (!StringUtils.isEmpty(tOrderInfoDTO.getEndDriverId())) {
            GetRequest getRequest = new GetRequest("t_end_user_info", tOrderInfoDTO.getEndDriverId().toString());
            tOrderInfoDTO.setEui((TEndUserInfo) esSearchUtil.get(getRequest, TEndUserInfo.class));
        }
        //euic
        if (!StringUtils.isEmpty(tOrderInfoDTO.getEndCarOwnerId())) {
            GetRequest getRequest = new GetRequest("t_end_user_info", tOrderInfoDTO.getEndCarOwnerId().toString());
            tOrderInfoDTO.setEuic((TEndUserInfo) esSearchUtil.get(getRequest, TEndUserInfo.class));
        }
        //euis
        if (!StringUtils.isEmpty(tOrderInfoDTO.getEndAgentId())) {
            GetRequest getRequest = new GetRequest("t_end_user_info", tOrderInfoDTO.getEndAgentId().toString());
            tOrderInfoDTO.setEuis((TEndUserInfo) esSearchUtil.get(getRequest, TEndUserInfo.class));
        }
        //wcb
        if (!StringUtils.isEmpty(tOrderInfoDTO.getCode())) {
            SearchRequest searchRequest = new SearchRequest("t_wallet_change_log");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
            boolBuilder.must(QueryBuilders.termQuery("innerTradeNo.keyword", tOrderInfoDTO.getCode()));
            boolBuilder.must(QueryBuilders.termQuery("tradeType.keyword", "BYUNFEIZHICHU"));
            FieldSortBuilder fsb = SortBuilders.fieldSort("id");
            fsb.order(SortOrder.DESC);
            sourceBuilder.sort(fsb);
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setWcb((TWalletChangeLog) esSearchUtil.search(searchRequest, TWalletChangeLog.class));
        }
        //wcl
        if (!StringUtils.isEmpty(tOrderInfoDTO.getCode())) {
            SearchRequest searchRequest = new SearchRequest("t_wallet_change_log");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
            boolBuilder.must(QueryBuilders.termQuery("tradeType.keyword", "CTIXIAN"));
            boolBuilder.must(QueryBuilders.termQuery("innerTradeNo.keyword", tOrderInfoDTO.getCode()));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setWcb((TWalletChangeLog) esSearchUtil.search(searchRequest, TWalletChangeLog.class));
        }
        //occ
        if (!StringUtils.isEmpty(tOrderInfoDTO.getCode())) {
            SearchRequest searchRequest = new SearchRequest("t_order_cast_changes");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
            boolBuilder.must(QueryBuilders.termQuery("dataEnable", true));
            boolBuilder.must(QueryBuilders.termQuery("orderCode.keyword", tOrderInfoDTO.getCode()));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setOcc((TOrderCastChanges) esSearchUtil.search(searchRequest, TOrderCastChanges.class));
        }
        //tdci
        if (!StringUtils.isEmpty(tOrderInfoDTO.getOcc())) {
            SearchRequest searchRequest = new SearchRequest("t_dic_cat_item");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            sourceBuilder.query(QueryBuilders.termQuery("orderCode.keyword", tOrderInfoDTO.getOcc().getCapitalTransferType()));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setTdci((TDicCatItem) esSearchUtil.search(searchRequest, TDicCatItem.class));
        }
        //ctp
        if (!StringUtils.isEmpty(tOrderInfoDTO.getOrderCreateType())) {
            SearchRequest searchRequest = new SearchRequest("t_dic_cat_item");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            sourceBuilder.query(QueryBuilders.termQuery("itemCode.keyword", tOrderInfoDTO.getOrderCreateType()));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setTdci((TDicCatItem) esSearchUtil.search(searchRequest, TDicCatItem.class));
        }
        //tcpi
        if (!StringUtils.isEmpty(tOrderInfoDTO.getCarrierId())) {
            GetRequest getRequest = new GetRequest("t_carrier_info", tOrderInfoDTO.getCarrierId().toString());
            tOrderInfoDTO.setTcpi((TCarrierInfo) esSearchUtil.get(getRequest, TCarrierInfo.class));
        }
        //tcp
        if (!StringUtils.isEmpty(tOrderInfoDTO.getCompanyProjectId())) {
            GetRequest getRequest = new GetRequest("t_company_project", tOrderInfoDTO.getCompanyProjectId().toString());
            tOrderInfoDTO.setTcp((TCompanyProject) esSearchUtil.get(getRequest, TCompanyProject.class));
        }
        //occs
        if (!StringUtils.isEmpty(tOrderInfoDTO.getCode())) {
            SearchRequest searchRequest = new SearchRequest("t_order_cast_calc_snapshot");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            sourceBuilder.query(QueryBuilders.termQuery("orderCode.keyword", tOrderInfoDTO.getCode()));
            FieldSortBuilder fsb = SortBuilders.fieldSort("id");
            fsb.order(SortOrder.DESC);
            sourceBuilder.sort(fsb);
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setOccs((TOrderCastCalcSnapshot) esSearchUtil.search(searchRequest, TOrderCastCalcSnapshot.class));
        }
        //tocc
        if (!StringUtils.isEmpty(tOrderInfoDTO.getCode())) {
            SearchRequest searchRequest = new SearchRequest("t_order_cast_changes");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
            boolBuilder.must(QueryBuilders.termQuery("orderCode .keyword", tOrderInfoDTO.getCode()));
            boolBuilder.must(QueryBuilders.termQuery("userOper.keyword", "PayMent"));
            FieldSortBuilder fsb = SortBuilders.fieldSort("id");
            fsb.order(SortOrder.DESC);
            sourceBuilder.sort(fsb);
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setTocc((TOrderCastChanges) esSearchUtil.search(searchRequest, TOrderCastChanges.class));
        }
        //occa
        if (StringUtils.isEmpty(tOrderInfoDTO.getCode())) {
            SearchRequest searchRequest = new SearchRequest("t_order_cast_changes");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
            boolBuilder.must(QueryBuilders.termQuery("orderCode.keyword", tOrderInfoDTO.getCode()));
            boolBuilder.must(QueryBuilders.termQuery("dataEnable", true));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setOcca((TOrderCastChanges) esSearchUtil.search(searchRequest, TOrderCastChanges.class));
        }
        //txfx
        if (!StringUtils.isEmpty(tOrderInfoDTO.getOcca().getWithdrawType())) {
            SearchRequest searchRequest = new SearchRequest("t_dic_cat_item");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            sourceBuilder.query(QueryBuilders.termQuery("withdrawType.keyword", tOrderInfoDTO.getOcca().getWithdrawType()));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setTxfx((TDicCatItem) esSearchUtil.search(searchRequest, TDicCatItem.class));
        }
        //txr
        if (!StringUtils.isEmpty(tOrderInfoDTO.getCode())) {
            SearchRequest searchRequest = new SearchRequest("t_order_cast_changes");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
            boolBuilder.must(QueryBuilders.termQuery("orderCode.keyword", tOrderInfoDTO.getCode()));
            boolBuilder.must(QueryBuilders.termQuery("userOper.keyword", "TX"));
            boolBuilder.must(QueryBuilders.termQuery("dataEnable", true));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setTxr((TOrderCastChanges) esSearchUtil.search(searchRequest, TOrderCastChanges.class));
        }
        //opd
        if (!StringUtils.isEmpty(tOrderInfoDTO.getCode())) {
            SearchRequest searchRequest = new SearchRequest("t_order_pack_detail");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
            boolBuilder.must(QueryBuilders.termQuery("orderCode.keyword", tOrderInfoDTO.getCode()));
            boolBuilder.must(QueryBuilders.termQuery("enable", false));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setOpd((TOrderPackDetail) esSearchUtil.search(searchRequest, TOrderPackDetail.class));
        }
        //opi
        if (!StringUtils.isEmpty(tOrderInfoDTO.getOpd().getPackPayCode())) {
            SearchRequest searchRequest = new SearchRequest("t_order_pack_info");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
            boolBuilder.must(QueryBuilders.termQuery("code.keyword", tOrderInfoDTO.getOpd().getPackPayCode()));
            boolBuilder.must(QueryBuilders.termQuery("enable", false));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setOpi((TOrderPackInfo) esSearchUtil.search(searchRequest, TOrderPackInfo.class));
        }
        //tosd
        if (!StringUtils.isEmpty(tOrderInfoDTO.getCode())) {
            SearchRequest searchRequest = new SearchRequest("t_order_pack_info");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
            boolBuilder.must(QueryBuilders.termQuery("orderCode.keyword", tOrderInfoDTO.getCode()));
            boolBuilder.must(QueryBuilders.termQuery("stateNodeValue", "SP0701"));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setTosd((TOrderState) esSearchUtil.search(searchRequest, TOrderState.class));
        }
        //euipk
        if (!StringUtils.isEmpty(tOrderInfoDTO.getOpi().getEndUserId())) {
            GetRequest getRequest = new GetRequest("t_end_user_info", tOrderInfoDTO.getOpi().getEndUserId().toString());
            tOrderInfoDTO.setEuipk((TEndUserInfo) esSearchUtil.get(getRequest, TEndUserInfo.class));
        }
        //tbc
        if (!StringUtils.isEmpty(tOrderInfoDTO.getOpi().getBankCardId())) {
            GetRequest getRequest = new GetRequest("t_bank_card", tOrderInfoDTO.getOpi().getBankCardId().toString());
            tOrderInfoDTO.setTbc((TBankCard) esSearchUtil.get(getRequest, TBankCard.class));
        }
        //tosup
        if (!StringUtils.isEmpty(tOrderInfoDTO.getCode())) {
            SearchRequest searchRequest = new SearchRequest("t_order_state");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
            boolBuilder.must(QueryBuilders.termQuery("stateNodeValue.keyword", "S0302"));
            boolBuilder.must(QueryBuilders.termQuery("orderCode.keyword", tOrderInfoDTO.getCode()));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setTosup((TOrderState) esSearchUtil.search(searchRequest, TOrderState.class));
        }

        //tosdown
        if (!StringUtils.isEmpty(tOrderInfoDTO.getCode()) ){
            SearchRequest searchRequest = new SearchRequest("t_order_state");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
            boolBuilder.must(QueryBuilders.termQuery("stateNodeValue.keyword", "S0402"));
            boolBuilder.must(QueryBuilders.termQuery("orderCode.keyword", tOrderInfoDTO.getCode()));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setTosdown((TOrderState) esSearchUtil.search(searchRequest, TOrderState.class));
        }
        //tos
        if (!StringUtils.isEmpty(tOrderInfoDTO.getCode())){
            SearchRequest searchRequest = new SearchRequest("t_order_state");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
            String[] strings=new String[]{"S1300","S1301","S1302"};
            boolBuilder.must(QueryBuilders.termQuery("stateNodeValue.keyword", strings));
            boolBuilder.must(QueryBuilders.termQuery("orderCode.keyword", tOrderInfoDTO.getCode()));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setTos((TOrderState) esSearchUtil.search(searchRequest, TOrderState.class));
        }
        //occv
        if (!StringUtils.isEmpty(tOrderInfoDTO.getCode())){
            SearchRequest searchRequest = new SearchRequest("t_order_state");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
            boolBuilder.must(QueryBuilders.termQuery("userOper.keyword", "Invoice"));
            boolBuilder.must(QueryBuilders.termQuery("orderCode.keyword", tOrderInfoDTO.getCode()));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setOccv((TOrderCastChanges) esSearchUtil.search(searchRequest, TOrderCastChanges.class));
        }
        //oal
        if(!StringUtils.isEmpty(tOrderInfoDTO.getCode())){
            SearchRequest searchRequest = new SearchRequest("t_order_audit_log");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            sourceBuilder.query(QueryBuilders.termQuery("orderCode.keyword", tOrderInfoDTO.getCode()));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setOal((TOrderAuditLog) esSearchUtil.search(searchRequest, TOrderAuditLog.class));
        }
        //todl
        if(!StringUtils.isEmpty(tOrderInfoDTO.getCode())){
            SearchRequest searchRequest = new SearchRequest("t_order_delete_log");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            sourceBuilder.query(QueryBuilders.termQuery("orderCode.keyword", tOrderInfoDTO.getCode()));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setTodl((TOrderDeleteLog) esSearchUtil.search(searchRequest, TOrderDeleteLog.class));
        }
        //tgsi
        if(!StringUtils.isEmpty(tOrderInfoDTO.getLineGoodsRelId())){
            SearchRequest searchRequest = new SearchRequest("t_goods_source_info");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            sourceBuilder.query(QueryBuilders.termQuery("lineGoodsRelId.keyword", tOrderInfoDTO.getLineGoodsRelId()));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setTgsi((TGoodsSourceInfo) esSearchUtil.search(searchRequest, TGoodsSourceInfo.class));
        }
        //toss
        if(!StringUtils.isEmpty(tOrderInfoDTO.getCode())){
            SearchRequest searchRequest = new SearchRequest("t_order_state");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
            boolBuilder.must(QueryBuilders.termQuery("stateNodeValue.keyword", "S0101"));
            boolBuilder.must(QueryBuilders.termQuery("orderCode.keyword", tOrderInfoDTO.getCode()));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setToss((TOrderState) esSearchUtil.search(searchRequest, TOrderState.class));
        }
        //tlgr
        if(!StringUtils.isEmpty(tOrderInfoDTO.getLineGoodsRelId())){
            GetRequest getRequest = new GetRequest("t_line_goods_rel", tOrderInfoDTO.getLineGoodsRelId().toString());
            tOrderInfoDTO.setTlgr((TLineGoodsRel) esSearchUtil.get(getRequest, TLineGoodsRel.class));
        }
        //tdci2
        if(!StringUtils.isEmpty(tOrderInfoDTO.getTlgr())&&
                !StringUtils.isEmpty(tOrderInfoDTO.getTlgr().getCapitalTransferType())
        ){
            SearchRequest searchRequest = new SearchRequest("t_dic_cat_item");
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            sourceBuilder.query(QueryBuilders.termQuery("itemCode.keyword", tOrderInfoDTO.getTlgr().getCapitalTransferType()));
            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
            searchRequest.source(sourceBuilder);
            tOrderInfoDTO.setTdci2((TDicCatItem) esSearchUtil.search(searchRequest, TDicCatItem.class));
        }

        return tOrderInfoDTO;
    }

    @Override
    public TOrderInfoDTO update(TOrderInfoDTO tOrderInfoDTO) {
        return tOrderInfoDTO;
    }

    @Override
    public TOrderInfoDTO delete(TOrderInfoDTO tOrderInfoDTO) {
        return tOrderInfoDTO;
    }
}